﻿using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for EditEventWindow.xaml
    /// </summary>
    public partial class TCYNET
    { 
      
         
         public TCYNET()
        {
            MV = new VABPOS();
            this.DataContext = MV;
            InitializeComponent(); 
        }  
      
        private void btnConvert_Click(object sender, RoutedEventArgs e)
        {
            DataSet SResult;
            SResult = new DataSet();
            SResult.Merge(MV.SetProd);
            EventDispatcher.Instance.RaiseStatus("YGRAV95启动", StatusEventType.StopProgress);
            string path = @"C:\IntexReport\Data\YGRAV95";
            try
            {
                SResult.Tables["ABPOS"].TableName = "ABPOS_EXT";
                INTEXBL.Save2Xml(SResult, path);
                //AsyncRun("YGRAV95","YGR", path);
                INTEXBL.AutoConvert(path, "YGRAV95");
                 DataRow[] rows = null;

                filter = "VKPAUFKRS='" + vm.KRS + "' AND VKPAUFLFD='" + vm.LFD + "' AND VKPAUFPOS='" + vm.POS + "'";

                rows = MV.SetEnv.Tables["VKPOS"].Select(filter);
                foreach (DataRow row in rows)
                {
                    row["VKPRESERV"] = row["VKPMENGE1"];
                }
                rows = MV.SetData.Tables["VKPOS"].Select(filter);
                foreach (DataRow row in rows)
                {
                    row["VKPRESERV"] = row["VKPMENGE1"];
                } 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }


        private void btnDeleteABON_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string krs = dwVKP["VKPAUFKRS"].ToString();
                string lfd = dwVKP["VKPAUFLFD"].ToString();
                string pos = dwVKP["VKPAUFPOS"].ToString();

                TMV.ITXABPLANData.DeleteAV95(krs, lfd, pos);
                DataRow dwData =TMV.QTB.SetProd.Tables["ICC_QUERYTB"].NewRow();
                dwData["VKPMANDANT"] = app.Mandant;
                dwData["VKPAUFKRS"] = krs;
                dwData["VKPAUFLFD"] = lfd;
                dwData["VKPAUFPOS"] = pos;
                dwData["C20"] = 0;
                INTEXDBC.UpdateVKPOS(dwData, app.company, 6);
                dwData["GAMANDANT"] = app.Mandant;
                dwData["GAAUFKRS"] = krs;
                dwData["GAAUFLFD"] = lfd;
                dwData["GAAUFPOS"] = pos;
                dwData["C20"] = 0;
                INTEXDBC.UpdateGAAUF(dwData, 6);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void btnPrintAV95_Click(object sender, RoutedEventArgs e)
        {

        } 
    }
}
